﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Text;
using System.Xml.Serialization;
using System.IO;

using segDroopyEyes.Eco.Services.XmlQueryService2;
using Axiom.Math;
using IDE;

using VisualDM.Model;

namespace VDMEditor
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            //MCSharp.Session.Init();
            var main_log = CommonClasses.Logger.LoggerManager.CreateOnce(".\\LoggerManager.ih.config", ".\\logs");

            IDEEcoSpace ecoSpace = new IDEEcoSpace(main_log.GetLogger("VDMEditorLogger"));
            ecoSpace.Active = true;

/*            var loader = new VisualDMLoader(ecoSpace);
//            loader.LoadVisualDM("WorkVDM.main.vdm");
            GenVDM(ecoSpace);
            loader.SaveVisualDMToFile(
                Path.GetDirectoryName(Application.ExecutablePath) + @"\querys", @"RMSI\RMSI.main.vdm");*/

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new VDMEditor());
        }

        private static VisualDomainModel GenVDM(IDEEcoSpace ecoSpace)
        {
            #region Stanki
            VisualDomainModel VDM = new VisualDomainModel(ecoSpace);
            VDM.Scene = new Scene(ecoSpace) { Name = "Scene", ID = 1 };
            VDM.Scene.DefaultPosition.Vector = new Vector3(0f, 0f, 0f);
            VDM.Scene.DefaultOrientation.Quaternion = Quaternion.Identity;
            VDM.Scene.DefaultScale.Vector = new Vector3(1, 1, 1);

            VisibleSceneObject o1;
            MeshResource mres;
            MaterialResource mat;
            VisibleSceneObject o2;
            Animation script;

            #region Piston

            o1 = new VisibleSceneObject(ecoSpace) { Name = "Shell", ID = 0x100 };
            o1.DefaultPosition.Vector = new Vector3(-40f, -20f, 47f);
            o1.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(0), Vector3.UnitX);
            o1.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_PistonShell.mesh" };
            o1.AddResource(mres);
            VDM.Scene.AddChildSceneObject(o1);

            o2 = new VisibleSceneObject(ecoSpace) { Name = "Piston", ID = 0x101 };
            o2.DefaultPosition.Vector = Vector3.Zero;
            o2.DefaultOrientation.Quaternion = Quaternion.Identity;
            o2.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_PistonSucker.mesh" };
            o2.AddResource(mres);
            o2.DefaultPosition.Vector = new Vector3(0, 0, 0);

            script = new Animation(ecoSpace)
            {
                Name = "PistonUp",
                LuaCode = @"
            PistonUp = coroutine.create(function ()
                local axis = 0;
                while Piston:GetState(axis) < 8 do
                    Piston:Translate(0, 1, 0);
                    Piston:SetState(axis, Piston:GetState(axis) + 1);
                    coroutine.yield();
                end;
                Modelling:PinStateChanged(28, 1);
            end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!26",
                NeedConnect = 3
            };
            o2.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "PistonDown",
                LuaCode = @"
            PistonDown = coroutine.create(function ()
                local axis = 0;
                while Piston:GetState(axis) > 0 do
                    Piston:Translate(0, -1, 0);
                    Piston:SetState(axis, Piston:GetState(axis) - 1);
                    coroutine.yield();
                end;
                Modelling:PinStateChanged(28, 0);
            end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!27",
                NeedConnect = 3
            };
            o2.AddAnimation(script);
            o1.AddChildSceneObject(o2);
            #endregion*/

            #region MP11
            #region Stan
            o1 = new VisibleSceneObject(ecoSpace) { Name = "MP11Stan", ID = 0x200 };
            o1.DefaultPosition.Vector = new Vector3(30, 2, 20.0f);
            o1.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(-25), Vector3.UnitY);
            o1.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP11Stan.mesh" };
            o1.AddResource(mres);
            VDM.Scene.AddChildSceneObject(o1);
            #endregion

            #region Table
            o2 = new VisibleSceneObject(ecoSpace) { Name = "MP11Table", ID = 0x201 };
            o2.DefaultPosition.Vector = new Vector3(0, 15, 0);
            o2.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(-45), Vector3.UnitY);
            o2.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP11Table.mesh" };
            o2.AddResource(mres);
            script = new Animation(ecoSpace)
            {
                Name = "MP11TableUp",

                LuaCode = @"
MP11TableUp = coroutine.create(function ()
    local axis = 0;
    while MP11Table:GetState(axis) < 5 do
        MP11Table:Translate(0, 0.5, 0);
        MP11Table:SetState(axis, MP11Table:GetState(axis) + 0.5);
        coroutine.yield();
    end;
    Modelling:PinStateChanged(13, 1);
end)"
                ,
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!31",
            };
            o2.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "MP11TableDown",

                LuaCode = @"
MP11TableDown = coroutine.create(function ()
    local axis = 0;
    while MP11Table:GetState(axis) > 0 do
        MP11Table:Translate(0, -0.5, 0);
        MP11Table:SetState(axis, MP11Table:GetState(axis) - 0.5);
        coroutine.yield();
    end;
    Modelling:PinStateChanged(13, 0);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!32"
            };
            o2.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "MP11TableRotateLeft",
                LuaCode = @"
MP11TableRotateLeft = coroutine.create(function ()
    local axis = 1;
    while MP11Table:GetState(axis) > 0 do
        MP11Table:Rotate(0, 1, 0, Modelling:GetSpeedRotation());
        MP11Table:SetState(axis, MP11Table:GetState(axis) - Modelling:GetSpeedEnviroment());
        coroutine.yield();
    end;
    Modelling:PinStateChanged(15, 0);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!34"
            };
            o2.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "MP11TableRotateRight",
                LuaCode = @"
MP11TableRotateRight = coroutine.create(function ()
    local axis = 1;
    while MP11Table:GetState(axis) < 25 do
        MP11Table:Rotate(0, 1, 0, -Modelling:GetSpeedRotation());
        MP11Table:SetState(axis, MP11Table:GetState(axis) + Modelling:GetSpeedEnviroment());
        coroutine.yield();
    end;
    Modelling:PinStateChanged(15, 1);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!33"
            };
            o2.AddAnimation(script);
            o1.AddChildSceneObject(o2);
            #endregion

            #region Upper Hand
            VisibleSceneObject o3 = new VisibleSceneObject(ecoSpace) { Name = "UpHandBar", ID = 0x202 };
            o3.DefaultPosition.Vector = new Vector3(0, 15.0f, 0);
            o3.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(0), Vector3.UnitY);
            o3.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP11HandBar.mesh" };
            o3.AddResource(mres);
            o2.AddChildSceneObject(o3);
            #endregion

            #region Upper Push
            VisibleSceneObject o4 = new VisibleSceneObject(ecoSpace) { Name = "UpPush", ID = 0x203 };
            o4.DefaultPosition.Vector = Vector3.Zero;
            o4.DefaultOrientation.Quaternion = Quaternion.Identity;
            o4.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP11UpHand.mesh" };
            o4.AddResource(mres);
            script = new Animation(ecoSpace)
            {
                Name = "MP11UPushForward",
                LuaCode = @"
MP11UPushForward = coroutine.create(function ()
    local axis = 0;
    while UpPush:GetState(axis) < 8 do
        UpPush:Translate(0, 0, 3);
        UpPush:SetState(axis, UpPush:GetState(axis) + 1);
        coroutine.yield();
    end;
    Modelling:PinStateChanged(0, 1);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!36"
            };
            o4.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "MP11UPushBackward",
                LuaCode = @"
MP11UPushBackward = coroutine.create(function ()
    local axis = 0;
    while UpPush:GetState(axis) > 0 do
        UpPush:Translate(0, 0, -3);
        UpPush:SetState(axis, UpPush:GetState(axis) - 1);
        coroutine.yield();
    end;
    Modelling:PinStateChanged(0, 0);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!37"
            };
            o4.AddAnimation(script);
            o3.AddChildSceneObject(o4);
            #endregion

            #region Upper Arm
            VisibleSceneObject o5 = new VisibleSceneObject(ecoSpace) { Name = "UpArm", ID = 0x204 };
            o5.DefaultPosition.Vector = new Vector3(0, 0f, 40.0f);
            o5.DefaultOrientation.Quaternion = Quaternion.Identity;
            o5.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP11UpArm.mesh" };
            o5.AddResource(mres);
            script = new Animation(ecoSpace)
            {
                Name = "MP11UArmOpen",
                LuaCode = @"
MP11UArmOpen = coroutine.create(function ()
    local axis = 1;
    while UpArm:GetState(axis) > 0 do
        UpRFinger:Rotate(0, 1, 0, -Modelling:GetSpeedRotation());
        UpLFinger:Rotate(0, 1, 0, Modelling:GetSpeedRotation());
        UpArm:SetState(axis, UpArm:GetState(axis) - Modelling:GetSpeedEnviroment());
        coroutine.yield();
    end;
    Modelling:PinStateChanged(6, 0);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!14",
                NeedConnect=2
            };
            o5.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "MP11UArmClose",
                LuaCode = @"
MP11UArmClose = coroutine.create(function ()
    local axis = 1;
    while UpArm:GetState(axis) < 30 do
        UpRFinger:Rotate(0, 1, 0, Modelling:GetSpeedRotation());
        UpLFinger:Rotate(0, 1, 0, -Modelling:GetSpeedRotation());
        UpArm:SetState(axis, UpArm:GetState(axis) + Modelling:GetSpeedEnviroment());
        coroutine.yield();
    end;
    Modelling:PinStateChanged(6, 1);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!13",
                NeedConnect = 1
            };
            o5.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "MP11UArmRotateLeft",
                LuaCode = @"
MP11UArmRotateLeft = coroutine.create(function ()
    local axis = 0;
    while UpArm:GetState(axis) > 0 do
        UpArm:Rotate(0, 0, 1, -Modelling:GetSpeedRotation());
        UpArm:SetState(axis, UpArm:GetState(axis) - Modelling:GetSpeedEnviroment());
        coroutine.yield();
    end;
    Modelling:PinStateChanged(3, 0);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!43",
            };
            o5.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "MP11UArmRotateRight",
                LuaCode = @"
MP11UArmRotateRight = coroutine.create(function ()
    local axis = 0;
    while UpArm:GetState(axis) < 180 do
        UpArm:Rotate(0, 0, 1, Modelling:GetSpeedRotation());
        UpArm:SetState(axis, UpArm:GetState(axis) + Modelling:GetSpeedEnviroment());
        coroutine.yield();
    end;
    Modelling:PinStateChanged(3, 1);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!42"
            };
            o5.AddAnimation(script);
            o4.AddChildSceneObject(o5);
            #endregion

            #region Upper Left Finger
            VisibleSceneObject o6 = new VisibleSceneObject(ecoSpace) { Name = "UpLFinger", ID = 0x205 };
            o6.DefaultPosition.Vector = new Vector3(6f, 0, 8f);
            o6.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(15), Vector3.UnitY);
            o6.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP11Finger.mesh" };
            o6.AddResource(mres);
            o5.AddChildSceneObject(o6);
            #endregion

            #region Upper Right Finger
            VisibleSceneObject o7 = new VisibleSceneObject(ecoSpace) { Name = "UpRFinger", ID = 0x206 };
            o7.DefaultPosition.Vector = new Vector3(-6f, 0, 8f);
            o7.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(-15), Vector3.UnitY);
            o7.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP11Finger.mesh" };
            o7.AddResource(mres);
            o5.AddChildSceneObject(o7);
            #endregion

            #region Low Hand
            o3 = new VisibleSceneObject(ecoSpace) { Name = "LHand", ID = 0x207 };
            o3.DefaultPosition.Vector = new Vector3(0, 7.5f, 0);
            o3.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(34), Vector3.UnitY);
            o3.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP11HandBar.mesh" };
            o3.AddResource(mres);
            o2.AddChildSceneObject(o3);
            #endregion

            #region Low Push
            o4 = new VisibleSceneObject(ecoSpace) { Name = "LPush", ID = 0x208 };
            o4.DefaultPosition.Vector = Vector3.Zero;
            o4.DefaultOrientation.Quaternion = Quaternion.Identity;
            o4.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP11DownHand.mesh" };
            o4.AddResource(mres);
            script = new Animation(ecoSpace)
            {
                Name = "MP11LPushForward",
                LuaCode = @"
MP11LPushForward = coroutine.create(function ()
    local axis = 0;
    while LPush:GetState(axis) < 3 do
        LPush:Translate(0, 0, 3);
        LPush:SetState(axis, LPush:GetState(axis) + 1);
        coroutine.yield();
    end;
    Modelling:PinStateChanged(8, 1);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!28"
            };
            o4.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "MP11LPushBackward",
                LuaCode = @"
MP11LPushBackward = coroutine.create(function ()
    local axis = 0;
    while LPush:GetState(axis) > 0 do
        LPush:Translate(0, 0, -3);
        LPush:SetState(axis, LPush:GetState(axis) - 1);
        coroutine.yield();
    end;
    Modelling:PinStateChanged(8, 0);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!29"
            };
            o4.AddAnimation(script);
            o3.AddChildSceneObject(o4);
            #endregion

            #region Low Arm
            o5 = new VisibleSceneObject(ecoSpace) { Name = "LArmMove", ID = 0x209 };
            o5.DefaultPosition.Vector = new Vector3(0, 0, 40f);
            o5.DefaultOrientation.Quaternion = Quaternion.Identity;
            o5.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP11DownArmMove.mesh" };
            o5.AddResource(mres);
            script = new Animation(ecoSpace)
            {
                Name = "MP11LArmOpen",
                LuaCode = @"
MP11LArmOpen = coroutine.create(function ()
    local axis = 1;
    while LArm:GetState(axis) > 0 do
        LRFinger:Rotate(0, 1, 0, -Modelling:GetSpeedRotation());
        LLFinger:Rotate(0, 1, 0, Modelling:GetSpeedRotation());
        LArm:SetState(axis, LArm:GetState(axis) - Modelling:GetSpeedEnviroment());
        coroutine.yield();
    end;
    Modelling:PinStateChanged(11, 0);
end)
",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!20",
                NeedConnect=2
            };
            o5.AddAnimation(script);

            script = new Animation(ecoSpace)
            {
                Name = "MP11LArmClose",
                LuaCode = @"
MP11LArmClose = coroutine.create(function ()
    local axis = 1;
    while LArm:GetState(axis) < 30 do
        LRFinger:Rotate(0, 1, 0, Modelling:GetSpeedRotation());
        LLFinger:Rotate(0, 1, 0, -Modelling:GetSpeedRotation());
        LArm:SetState(axis, LArm:GetState(axis) + Modelling:GetSpeedEnviroment());
        coroutine.yield();
    end;
    Modelling:PinStateChanged(11, 1);
end)
",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!19",
                NeedConnect=1
            };
            o5.AddAnimation(script);
            o4.AddChildSceneObject(o5);
            #endregion

            #region Low Hand

            VisibleSceneObject o13 = new VisibleSceneObject(ecoSpace) { Name = "MP11DownArm", ID = 0x2081 };
            o13.DefaultPosition.Vector = new Vector3(0, 7.5f, 0);
            o13.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(34), Vector3.UnitY);
            o13.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP11DownArm.mesh" };
            o13.AddResource(mres);
            o5.AddChildSceneObject(o13);
            #endregion

            #region Low Left Finger
            o6 = new VisibleSceneObject(ecoSpace) { Name = "LLFinger", ID = 0x210 };
            o6.DefaultPosition.Vector = new Vector3(6f, 0, 8f);
            o6.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(15), Vector3.UnitY);
            o6.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP11Finger.mesh" };
            o6.AddResource(mres);
            o5.AddChildSceneObject(o6);
            #endregion

            #region Low Right Finger
            o7 = new VisibleSceneObject(ecoSpace) { Name = "LRFinger", ID = 0x211 };
            o7.DefaultPosition.Vector = new Vector3(-6f, 0, 8f);
            o7.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(-15), Vector3.UnitY);
            o7.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP11Finger.mesh" };
            o7.AddResource(mres);
            o5.AddChildSceneObject(o7);
            #endregion

            #endregion

            #region mp9

            #region Stan
            o1 = new VisibleSceneObject(ecoSpace) { Name = "MP9Stan", ID = 0x300 };
            o1.DefaultPosition.Vector = new Vector3(-35f, 0, 125f);
            o1.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(143), Vector3.UnitY);
            o1.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP9Stan.mesh" };
            o1.AddResource(mres);
            VDM.Scene.AddChildSceneObject(o1);
            #endregion

            #region Table
            o2 = new VisibleSceneObject(ecoSpace) { Name = "MP9Table", ID = 0x301 };
            o2.DefaultPosition.Vector = new Vector3(0, 15.0f, 0);
            o2.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(10), Vector3.UnitY);
            o2.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP9Table.mesh" };
            o2.AddResource(mres);

            script = new Animation(ecoSpace)
            {
                Name = "MP9TableUp",
                LuaCode = @"
MP9TableUp = coroutine.create(function ()
    local axis = 0;
    while MP9Table:GetState(axis) < 5 do
        MP9Table:Translate(0, 0.5, 0);
        MP9Table:SetState(axis, MP9Table:GetState(axis) + 0.5);
        coroutine.yield();
    end;
    Modelling:PinStateChanged(23, 1);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!38"
            };
            o2.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "MP9TableDown",
                LuaCode = @"
MP9TableDown = coroutine.create(function ()
    local axis = 0;
    while MP9Table:GetState(axis) > 0 do
        MP9Table:Translate(0, -0.5, 0);
        MP9Table:SetState(axis, MP9Table:GetState(axis) - 0.5);
        coroutine.yield();
    end;
    Modelling:PinStateChanged(23, 0);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!39"
            };
            o2.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "MP9TableRotateLeft",
                LuaCode = @"
MP9TableRotateLeft = coroutine.create(function ()
    local axis = 1;
    while MP9Table:GetState(axis) > 0 do
        MP9Table:Rotate(0, 1, 0, Modelling:GetSpeedRotation());
        MP9Table:SetState(axis, MP9Table:GetState(axis) - Modelling:GetSpeedEnviroment());
        coroutine.yield();
    end;
    Modelling:PinStateChanged(25, 0);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!17"
            };
            o2.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "MP9TableRotateRight",
                LuaCode = @"
MP9TableRotateRight = coroutine.create(function ()
    local axis = 1;
    while MP9Table:GetState(axis) < 30 do
        MP9Table:Rotate(0, 1, 0, -Modelling:GetSpeedRotation());
        MP9Table:SetState(axis, MP9Table:GetState(axis) + Modelling:GetSpeedEnviroment());
        coroutine.yield();
    end;
    Modelling:PinStateChanged(25, 1);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!16"
            };
            o2.AddAnimation(script);
            o1.AddChildSceneObject(o2);
            #endregion

            #region Upper Hand
            o3 = new VisibleSceneObject(ecoSpace) { Name = "MP9Hand", ID = 0x302 };
            o3.DefaultPosition.Vector = new Vector3(0, 7.5f, 0);
            o3.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(30), Vector3.UnitY);
            o3.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP9HandBar.mesh" };
            o3.AddResource(mres);
            o2.AddChildSceneObject(o3);
            #endregion

            #region Push
            o4 = new VisibleSceneObject(ecoSpace) { Name = "MP9Push", ID = 0x303 };
            o4.DefaultPosition.Vector = Vector3.Zero;
            o4.DefaultOrientation.Quaternion = Quaternion.Identity;
            o4.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP9Hand.mesh" };
            o4.AddResource(mres);
            script = new Animation(ecoSpace)
            {
                Name = "MP9UPPushForward",
                LuaCode = @"
MP9UPPushForward = coroutine.create(function ()
    local axis = 0;
    while MP9Push:GetState(axis) < 3 do
        MP9Push:Translate(0, 0, 3);
        MP9Push:SetState(axis, MP9Push:GetState(axis) + 1);
        coroutine.yield();
    end;
    Modelling:PinStateChanged(18, 1);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!24"
            };
            o4.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "MP9UPushBackWard",
                LuaCode = @"
MP9UPushBackWard = coroutine.create(function ()
    local axis = 0;
    while MP9Push:GetState(axis) > 0 do
        MP9Push:Translate(0, 0, -3);
        MP9Push:SetState(axis, MP9Push:GetState(axis) - 1);
        coroutine.yield();
    end;
    Modelling:PinStateChanged(18, 0);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!25"
            };
            o4.AddAnimation(script);
            o3.AddChildSceneObject(o4);
            #endregion

            #region Upper Arm
            o5 = new VisibleSceneObject(ecoSpace) { Name = "RMSI_MP9Arm", ID = 0x304 };
            o5.DefaultPosition.Vector = new Vector3(0, 0, 40f);
            o5.DefaultOrientation.Quaternion = Quaternion.Identity;
            o5.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP9Arm.mesh" };
            o5.AddResource(mres);
            script = new Animation(ecoSpace)
            {
                Name = "MP9ArmOpen",
                LuaCode = @"
MP9ArmOpen = coroutine.create(function ()
    local axis = 1;
    while MP9Arm:GetState(axis) > 0 do
        MP9RFinger:Rotate(0, 1, 0, -Modelling:GetSpeedRotation());
        MP9LFinger:Rotate(0, 1, 0, Modelling:GetSpeedRotation());
        MP9Arm:SetState(axis, MP9Arm:GetState(axis) - Modelling:GetSpeedEnviroment());
        coroutine.yield();
    end;
    Modelling:PinStateChanged(21, 0);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!23",
                NeedConnect=2
            };
            o5.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "MP9ArmClose",
                LuaCode = @"
MP9ArmClose = coroutine.create(function ()
    local axis = 1;
    while MP9Arm:GetState(axis) < 30 do
        MP9RFinger:Rotate(0, 1, 0, Modelling:GetSpeedRotation());
        MP9LFinger:Rotate(0, 1, 0, -Modelling:GetSpeedRotation());
        MP9Arm:SetState(axis, MP9Arm:GetState(axis) + Modelling:GetSpeedEnviroment());
        coroutine.yield();
    end;
    Modelling:PinStateChanged(21, 1);
end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!22",
                NeedConnect=1
            };
            o5.AddAnimation(script);
            o4.AddChildSceneObject(o5);
            #endregion

            #region Left Finger
            o6 = new VisibleSceneObject(ecoSpace) { Name = "MP9LFinger", ID = 0x305 };
            o6.DefaultPosition.Vector = new Vector3(6f, 0, 8f);
            o6.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(15), Vector3.UnitY);
            o6.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP9Finger.mesh" };
            o6.AddResource(mres);
            o5.AddChildSceneObject(o6);
            #endregion

            #region Upper Right Finger
            o7 = new VisibleSceneObject(ecoSpace) { Name = "MP9RFinger", ID = 0x306 };
            o7.DefaultPosition.Vector = new Vector3(-6f, 0, 8f);
            o7.DefaultOrientation.Quaternion = Quaternion.FromAngleAxis(Axiom.Math.Utility.DegreesToRadians(-15), Vector3.UnitY);
            o7.DefaultScale.Vector = new Vector3(1, 1, 1);
            mres = new MeshResource(ecoSpace) { FileName = "RMSI_MP9Finger.mesh" };
            o7.AddResource(mres);
            o5.AddChildSceneObject(o7);
            #endregion
            
            #endregion

            #region Modelling

            SceneObject modelling = new SceneObject(ecoSpace) { Name = "Modelling", ID = 0x10 };
            script = new Animation(ecoSpace)
            {
                Name = "SetCheckPoint",
                LuaCode = @"
SetCheckPoint = coroutine.create(
    function ()
        Modelling:SetCheckPoint();
    end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!40"
            };
            modelling.AddAnimation(script);
            script = new Animation(ecoSpace)
            {
                Name = "RollBack",
                LuaCode = @"
RollBack = coroutine.create(
    function ()
        Modelling:RollBack();
    end)",
                MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!41"
            };
            modelling.AddAnimation(script);

            VDM.Scene.AddChildSceneObject(modelling);

            #endregion

/*            #region Supports

            o1 = new VisibleSceneObject(ecoSpace) { Name = "Bolv_Cylinder1", ID = 0x400 };
            o1.DefaultPosition.Vector = new Vector3(-50f, 19f, 51f);
            o1.DefaultOrientation.Quaternion = Quaternion.Identity;
            o1.DefaultScale.Vector = new Vector3(1f, 1f, 1f);
            mres = new MeshResource(ecoSpace) { FileName = "Cylinder01.mesh" };
            o1.AddResource(mres);
            mat = new MaterialResource(ecoSpace) { FileName = "Piston_Shell.material", Name = "Bolv_Mat" };
            o1.AddResource(mat);
            VDM.Scene.AddChildSceneObject(o1);
            o1 = new VisibleSceneObject(ecoSpace) { Name = "Bolv_Cylinder2", ID = 0x401 };
            o1.DefaultPosition.Vector = new Vector3(-5f, 19f, 51f);
            o1.DefaultOrientation.Quaternion = Quaternion.Identity;
            o1.DefaultScale.Vector = new Vector3(1f, 1f, 1f);
            mres = new MeshResource(ecoSpace) { FileName = "Cylinder01.mesh" };
            o1.AddResource(mres);
            mat = new MaterialResource(ecoSpace) { FileName = "Piston_Shell.material", Name = "Bolv_Mat" };
            o1.AddResource(mat);
            VDM.Scene.AddChildSceneObject(o1);

            o1 = new VisibleSceneObject(ecoSpace) { Name = "Support1", ID = 0x402, TypeModelling = 1 };
            o1.DefaultPosition.Vector = new Vector3(-10f, -10f, 70f);

            o1.DefaultOrientation.Quaternion = new Quaternion(0.6532815f, -0.6532815f, 0.2705981f, 0.2705981f);
            
            o1.DefaultScale.Vector = new Vector3(2.1f, 2.9f, 2.7f);
            mres = new MeshResource(ecoSpace) { FileName = "Support1.mesh" };
            o1.AddResource(mres);
            mat = new MaterialResource(ecoSpace) { FileName = "MP11final.material", Name = "MSupport" };
            o1.AddResource(mat);
            VDM.Scene.AddChildSceneObject(o1);

            o1 = new VisibleSceneObject(ecoSpace) { Name = "Support2", ID = 0x403 };
            o1.DefaultPosition.Vector = new Vector3(-140, -10, 55);
            o1.DefaultOrientation.Quaternion = new Quaternion(0.5f, -0.5f, -0.5f, -0.5f);
            o1.DefaultScale.Vector = new Vector3(2.5f, 2.2f, 2.7f);
            mres = new MeshResource(ecoSpace) { FileName = "Support2.mesh" };
            o1.AddResource(mres);
            mat = new MaterialResource(ecoSpace) { FileName = "Piston_Shell.material", Name = "MSupport" };
            o1.AddResource(mat);
            VDM.Scene.AddChildSceneObject(o1);

            #endregion*/
            #endregion

            #region MILP
/*            VisualDomainModel VDM = new VisualDomainModel(ecoSpace);
            VDM.Scene = new Scene(ecoSpace) { Name = "Scene", ID = 1 };
            VDM.Scene.DefaultPosition.Vector = new Vector3(0, 0, 0);
            VDM.Scene.DefaultOrientation.Quaternion = Quaternion.Identity;
            VDM.Scene.DefaultScale.Vector = new Vector3(1, 1, 1);

            VisibleSceneObject o1;
            MeshResource mres;
            MaterialResource mat;
            Animation script;

            #region MP11

            #region MP11 STAN
                o1 = new VisibleSceneObject(ecoSpace) { Name = "MP11Stan", ID = 0x100 };
                o1.DefaultPosition.Vector = new Vector3(0.0f, 0.0f, 0.0f);
                o1.DefaultOrientation.Quaternion = Quaternion.Identity;//.FromAngleAxis(Utility.DegreesToRadians(0), Vector3.UnitX);
                o1.DefaultScale.Vector = new Vector3(1, 1, 1);
                mres = new MeshResource(ecoSpace) { FileName = "MP11Stan.mesh" };
                o1.AddResource(mres);
                VDM.Scene.AddChildSceneObject(o1);
            #endregion

            #region MP11 TABLE
                VisibleSceneObject o2 = new VisibleSceneObject(ecoSpace) { Name = "MP11Table", ID = 0x101 };
                o2.DefaultPosition.Vector = new Vector3(0.0f, 20.0f, 0.0f);
                o2.DefaultOrientation.Quaternion = Quaternion.Identity;//.FromAngleAxis(Utility.DegreesToRadians(0), Vector3.UnitX);
                o2.DefaultScale.Vector = new Vector3(1, 1, 1);
                mres = new MeshResource(ecoSpace) { FileName = "MP11Table.mesh" };
                o2.AddResource(mres);
                o1.AddChildSceneObject(o2);
            #endregion

            #region MP11 DownHandBar
                VisibleSceneObject o3 = new VisibleSceneObject(ecoSpace) { Name = "MP11DownHandBar", ID = 0x102 };
                o3.DefaultPosition.Vector = new Vector3(0.0f, 5.0f, 0.0f);
                o3.DefaultOrientation.Quaternion = Quaternion.Identity;//.FromAngleAxis(Utility.DegreesToRadians(0), Vector3.UnitX);
                o3.DefaultScale.Vector = new Vector3(1, 1, 1);
                mres = new MeshResource(ecoSpace) { FileName = "MP11HandBar.mesh" };
                o3.AddResource(mres);
                o2.AddChildSceneObject(o3);
            #endregion

            #region MP11 DownHand
                VisibleSceneObject o4 = new VisibleSceneObject(ecoSpace) { Name = "MP11DownHand", ID = 0x103 };
                o4.DefaultPosition.Vector = new Vector3(0.0f, 0.0f, 0.0f);
                o4.DefaultOrientation.Quaternion = Quaternion.Identity;//.FromAngleAxis(Utility.DegreesToRadians(0), Vector3.UnitX);
                o4.DefaultScale.Vector = new Vector3(1, 1, 1);
                mres = new MeshResource(ecoSpace) { FileName = "MP11DownHand.mesh" };
                o4.AddResource(mres);
                o3.AddChildSceneObject(o4);
            #endregion

            #region MP11 DownArm
                VisibleSceneObject o5 = new VisibleSceneObject(ecoSpace) { Name = "MP11DownArm", ID = 0x104 };
                o5.DefaultPosition.Vector = new Vector3(10.0f, 0.0f, 0.0f);
                o5.DefaultOrientation.Quaternion = Quaternion.Identity;//.FromAngleAxis(Utility.DegreesToRadians(0), Vector3.UnitX);
                o5.DefaultScale.Vector = new Vector3(1, 1, 1);
                mres = new MeshResource(ecoSpace) { FileName = "MP11DownArm.mesh" };
                o5.AddResource(mres);
                o4.AddChildSceneObject(o5);
            #endregion

                #region MP11 UpHandBar
                o3 = new VisibleSceneObject(ecoSpace) { Name = "MP11UpHandBar", ID = 0x105 };
                o3.DefaultPosition.Vector = new Vector3(0.0f, 10.0f, 0.0f);
                o3.DefaultOrientation.Quaternion = Quaternion.Identity;//.FromAngleAxis(Utility.DegreesToRadians(0), Vector3.UnitX);
                o3.DefaultScale.Vector = new Vector3(1, 1, 1);
                mres = new MeshResource(ecoSpace) { FileName = "MP11HandBar.mesh" };
                o3.AddResource(mres);
                o2.AddChildSceneObject(o3);
                #endregion

            #region MP11 UpHand
                o4 = new VisibleSceneObject(ecoSpace) { Name = "MP11UpHand", ID = 0x106 };
                o4.DefaultPosition.Vector = new Vector3(0.0f, 0.0f, 0.0f);
                o4.DefaultOrientation.Quaternion = Quaternion.Identity;//.FromAngleAxis(Utility.DegreesToRadians(0), Vector3.UnitX);
                o4.DefaultScale.Vector = new Vector3(1, 1, 1);
                mres = new MeshResource(ecoSpace) { FileName = "MP11UpHand.mesh" };
                o4.AddResource(mres);
                o3.AddChildSceneObject(o4);
            #endregion

            #region MP11 UpArm
                o5 = new VisibleSceneObject(ecoSpace) { Name = "MP11UpArm", ID = 0x107 };
                o5.DefaultPosition.Vector = new Vector3(20.0f, 0.0f, 0.0f);
                o5.DefaultOrientation.Quaternion = Quaternion.Identity;//.FromAngleAxis(Utility.DegreesToRadians(0), Vector3.UnitX);
                o5.DefaultScale.Vector = new Vector3(1, 1, 1);
                mres = new MeshResource(ecoSpace) { FileName = "MP11UpArm.mesh" };
                o5.AddResource(mres);
                o4.AddChildSceneObject(o5);
            #endregion

            #region MP11 Finger
                VisibleSceneObject o6 = new VisibleSceneObject(ecoSpace) { Name = "MP11FingerL", ID = 0x108 };
                o6.DefaultPosition.Vector = new Vector3(5.0f, 0.0f, 0.0f);
                o6.DefaultOrientation.Quaternion = Quaternion.Identity;//.FromAngleAxis(Utility.DegreesToRadians(0), Vector3.UnitX);
                o6.DefaultScale.Vector = new Vector3(1, 1, 1);
                mres = new MeshResource(ecoSpace) { FileName = "MP11Finger.mesh" };
                o6.AddResource(mres);
                o5.AddChildSceneObject(o6);
            #endregion

            #region MP11 Finger
                o6 = new VisibleSceneObject(ecoSpace) { Name = "MP11FingerR", ID = 0x109 };
                o6.DefaultPosition.Vector = new Vector3(50.0f, 0.0f, 10.0f);
                o6.DefaultOrientation.Quaternion = Quaternion.Identity;//.FromAngleAxis(Utility.DegreesToRadians(0), Vector3.UnitX);
                o6.DefaultScale.Vector = new Vector3(1, 1, 1);
                mres = new MeshResource(ecoSpace) { FileName = "MP11Finger.mesh" };
                o6.AddResource(mres);
                o5.AddChildSceneObject(o6);
            #endregion

            #endregion

            #region STOVE
                o1 = new VisibleSceneObject(ecoSpace) { Name = "Stove", ID = 0x110 };
                o1.DefaultPosition.Vector = new Vector3(20.0f, 20.0f, 0.0f);
                o1.DefaultOrientation.Quaternion = Quaternion.Identity;//.FromAngleAxis(Utility.DegreesToRadians(0), Vector3.UnitX);
                o1.DefaultScale.Vector = new Vector3(1, 1, 1);
                mres = new MeshResource(ecoSpace) { FileName = "Stove.mesh" };
                o1.AddResource(mres);
                VDM.Scene.AddChildSceneObject(o1);
            #endregion

            #region ChilCasting
                o1 = new VisibleSceneObject(ecoSpace) { Name = "CastingTable", ID = 0x111 };
                o1.DefaultPosition.Vector = new Vector3(50.0f, 50.0f, 0.0f);
                o1.DefaultOrientation.Quaternion = Quaternion.Identity;//.FromAngleAxis(Utility.DegreesToRadians(0), Vector3.UnitX);
                o1.DefaultScale.Vector = new Vector3(1, 1, 1);
                mres = new MeshResource(ecoSpace) { FileName = "ChillCastingTable.mesh" };
                o1.AddResource(mres);
                VDM.Scene.AddChildSceneObject(o1);

                o2 = new VisibleSceneObject(ecoSpace) { Name = "MovingCasting", ID = 0x112 };
                o2.DefaultPosition.Vector = new Vector3(10.0f, 5.0f, 0.0f);
                o2.DefaultOrientation.Quaternion = Quaternion.Identity;//.FromAngleAxis(Utility.DegreesToRadians(0), Vector3.UnitX);
                o2.DefaultScale.Vector = new Vector3(1, 1, 1);
                mres = new MeshResource(ecoSpace) { FileName = "MovingCasting.mesh" };
                o2.AddResource(mres);
                o1.AddChildSceneObject(o2);

            #endregion

                #region Modelling

                SceneObject modelling = new SceneObject(ecoSpace) { Name = "Modelling", ID = 0x20 };
                script = new Animation(ecoSpace)
                {
                    Name = "SetCheckPoint",
                    LuaCode = @"
SetCheckPoint = coroutine.create(
    function ()
        Modelling:SetCheckPoint();
    end)",
                    MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!40"
                };
                modelling.AddAnimation(script);
                script = new Animation(ecoSpace)
                {
                    Name = "RollBack",
                    LuaCode = @"
RollBack = coroutine.create(
    function ()
        Modelling:RollBack();
    end)",
                    MethodID = "$new$!b86e2b25-9769-46f6-9a51-0e9b6be06ca5!41"
                };
                modelling.AddAnimation(script);

                VDM.Scene.AddChildSceneObject(modelling);

            #endregion
            */
            #endregion

            return VDM;
        }
    }
}
